//
//  MeditationListViewController.m
//  AndCampus
//
//  Created by 史宵宵 on 2018/1/25.
//  Copyright © 2018年 史宵宵. All rights reserved.
//

#import "MeditationListViewController.h"
#import "MeditationListListTableViewCell.h"
#import "MeditationViewController.h"
@interface MeditationListViewController ()
@property (nonatomic,strong) NSMutableArray *dataArray;
@end

@implementation MeditationListViewController

-(NSMutableArray *)dataArray{
    if (!_dataArray) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, -20,kScreenW, kScreenH)];
    imageView.image=[UIImage imageNamed:@"meditationlist_bg"];
    self.tableView.backgroundView =imageView;
    self.title = @"冥想屋";
    
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([MeditationListListTableViewCell class]) bundle:nil] forCellReuseIdentifier:@"MeditationListListTableViewCell"];
    [self creatDataList];
}

- (void)creatDataList{
    YJNetWorkManger *yjNetWorkManger =  [YJNetWorkManger shareManager];
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
    //    [dic setValue:@"1" forKey:@"page"];   //页数 默认1
    //    [dic setValue:KREFRESHROWS forKey:@"rows"];   //每页数量
    [dic setValue:[Global getUserTokenInfo] forKey:@"token"]; //用户的token

    [yjNetWorkManger requestType:POST andURL:[JSPathUtil urlAppInterestGetThink] andParmas:dic andComplition:^(id response, BOOL isuccess) {
        if (isuccess) {
            //            if (self.pageNo == 1) {
            [self.dataArray removeAllObjects];
            //            }
            NSArray *array = [NSArray arrayWithArray:response];
            [MegaphoneInfo mj_setupReplacedKeyFromPropertyName:^NSDictionary *{
                return @{@"megaphoneId" : @"id"};
            }];
            [self.dataArray addObjectsFromArray:[MegaphoneInfo mj_objectArrayWithKeyValuesArray:array]];
             
            //            [self refreshCount:self.dataArray.count noDataText:@"还没有同班同学" totalRow:response[@"totalRow"]];
            [self.tableView reloadData];
        }
    }];
    
}
- (NSInteger )numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MeditationListListTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"MeditationListListTableViewCell" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor clearColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.megaphoneInfo = self.dataArray[indexPath.row];
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 100;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    MeditationViewController *meditationVC = [[MeditationViewController alloc]init];
    meditationVC.megaphoneInfo = self.dataArray[indexPath.row];
    [self.navigationController pushViewController:meditationVC animated:YES];
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [[UIView alloc]init];
    view.frame = CGRectZero;
    view.backgroundColor = KBACKGROUNDCOLOR;
    
    return view;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.01f;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
